草庐IT

android - asyncTask 测试不执行

全部标签

unit-testing - 测试一个 go 闭包

我有以下在golang中返回闭包的函数,任何想法/引用怎么可能为它编写测试?type(OrderRepoInterfaceinterface{funcsave(msgMessage)error}//OrderAggregationrepresentsaneventhandlerEventHandlerstruct{repoOrderRepoInterface//inmain.goipassaconcreterepositoryhere}VersionedEventHandlerstruct{functionfunc(msg*Message)error}Messagestruct{ver

go - AES CTR 失败测试向量(一个除外)

我正在Go中测试AESCTR。我写了加密/解密的逻辑。当然,我搜索了测试向量以验证我的加密/解密逻辑是否有效。第一个矢量通过但其余的不通过。如果有人可以结帐,我将不胜感激this代码被剪断并提示我失败的原因。typetestVectorstruct{plainTextstringcipherTextstring}funcmain(){//encryptionkeyencryptionKey,err:=hex.DecodeString("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")iferr!=nil

inheritance - 从没有将类型转换为继承类型的继承结构执行实际对象方法

packagemainimport("fmt")typeIAinterface{Parse()Name()string}typeAstruct{IA}func(a*A)Name()string{return"AName"}func(a*A)Parse(){fmt.Println("A-"+a.Name())}typeBstruct{A}func(b*B)Name()string{return"BName"}funcmain(){a:=&A{}b:=&B{}a.Parse()b.Parse()//Iwouldliketosee"A-BName"}Playground当我从继承结构执行方法

rest - 通过测试用例,同时给出 500 作为响应

request,err:=http.NewRequest("GET",path,nil)response:=httptest.NewRecorder()r.ServeHTTP(response,request)varrawmap[string]map[string]string_=json.Unmarshal(response.Body.Bytes(),&raw)details:=raw["response"]我有一个TestFunction,我在其中使用了这段代码。是代码测试GET请求的RESTAPI。在我的第一个测试用例中,我命中了一个定义的处理程序,而在第二个测试用例中,我命中了

go - 测试不同包中存在的方法

在写测试用例的时候发现了两个问题:有3个测试文件,其中one_test.go和two_test.go可以添加到server_suites_test.go和它运行良好。但是three_point_one_test.go的功能无法添加到server_suites_test.go中,因为无法导入_test.go。one_test.go和two_test.go使用由server_test.go创建的gRPC客户端对象。实际上,server_test.go创建了一个gRPC服务器和一个客户端,这个客户端被其他测试用例使用。当前three_point_one_test.go无法访问此客户端。因此,

go - 登录 Golang 测试用例

这个问题在这里已经有了答案:HowdoyouprintinaGotestusingthe"testing"package?(8个答案)关闭4年前。我有这个:packageutils_testimport("huru/utils""testing")funcTestSetFields(t*testing.T){t.Log("dest.Foo")src:=struct{}{}dest:=struct{}{}utils.SetFields(&src,&dest)t.Log("dest.Foo",dest)}然后我运行这个命令:gotest-runTestSetFields./src/huru

go - 在 golang 中执行 echo 和 openssl 命令

我正在尝试使用此cli命令读取远程网站ssl证书openssls_client-connectwww.yahoo.no:4432>/dev/null|opensslx509-noout-enddate|剪切-d=-f2。这在cli中工作正常,但是当我在golang中执行它时:packagemainimport("bytes""log""os/exec""time")funcmain(){cmd:=exec.Command("echo","|openssls_client-connectwww.yahoo.com:4432>/dev/null|opensslx509-noout-endd

go - 在 Go 中测试通过 json http 响应返回的错误

我目前正在使用Go开发一个图像处理程序,它旨在拒绝上传不受支持的文件。我的意图是让Go程序通过服务器http.ResponceWritter返回错误,详细说明拒绝的情况,作为json,供上传服务使用。如何在服务器代码中设置错误:typeErrorstruct{ImgHandlerError`json:"error"`}typeImgHandlerErrorstruct{Messagestring`json:"message"`Codestring`json:"code"`}funcMakeError(message,codestring)*Error{errorMessage:=&Er

unit-testing - 如何修复测试用例中的 "missing type in composite literal"

我正在尝试为函数ReadField()编写测试代码,但我在定义测试用例时遇到了困难。它给出了一个错误“复合文字中缺少类型”。我相信这只是一些语法错误。我已经尝试在函数体之外定义结构体,但它仍然会给出相同的错误。ReadField(string,string,bool)(bool,string)funcTestReadField(t*testing.T){testCases:=[]struct{NamestringInputstruct{FirstStringstringSecondStringstringSomeBoolbool}Expectedstruct{IsValidboolMe

go - 执行 UnmarshalExtJSON 时读取数组的无效请求

我正在尝试使用go.mongodb.org/mongo-driver/bson中的UnmarshalExtJSON将扩展的JSON解码为结构它给我一个错误:读取数组的请求无效如何将这些数据解码到我的结构中?MVCE:packagemainimport("fmt""go.mongodb.org/mongo-driver/bson")funcmain(){varjson="{\"data\":{\"streamInformation\":{\"codecs\":[\"avc1.640028\"]}}}"varworkflowWorkflowe:=bson.UnmarshalExtJSON(